package cn.matrix42.potoo.format.markdown.element.text.list;

import java.util.ArrayList;
import java.util.List;

import cn.matrix42.potoo.format.markdown.element.MarkdownElement;

public class OrderedList extends MarkdownElement {

    private int no = 1;

    private final List<OrderedElement> elementList = new ArrayList<>();

    public OrderedList() {
    }

    public void addItem(String item) {
        OrderedElement orderedElement = OrderedElement.of(no, item);
        orderedElement.setup(context);
        elementList.add(orderedElement);
        no++;
    }

    public List<OrderedElement> getElementList() {
        return elementList;
    }

    @Override
    public List<String> toMarkdownStringList() {
        List<String> list = new ArrayList<>();
        for (OrderedElement orderedElement : elementList) {
            list.add(orderedElement.toMarkdownString());
        }
        list.add(context.getConfig().getEof());
        return list;
    }

    public static OrderedList of() {
        return new OrderedList();
    }
}
